import { Controller } from "../../mvc/core/Controller";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { IView } from "../../mvc/interfaces/IView";
import { QrCodeModule } from "../../../modules/QrCodeModule";
import { DataEvent } from "../events/DataEvent";
import { QrCodeConst } from "../view/qrcode/QrCodeConst";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { ParamsConst } from "../../common/global/ParamsConst";
import { QrCodeHintBtnView } from "../view/qrcode/QrCodeHintBtnView";
//class QrCodeController
    
    export  class QrCodeController extends Controller
    {
       

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePromotionCardInfo, this.onPromotionCardInfoRes);
            Dispatcher.addEventListener(EventName.NoviceCardUseSuccess, this.onNoviceCardUseSuccessHandler);
            return;
        }

        protected /* override */ initView(): IView
        {
            if (_view == null) 
            {
                _view = new QrCodeModule();
            }
            return _view;
        }

        /* internal  */onNoviceCardUseSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            if (loc1 && loc1.type == QrCodeConst.CARD_TYPE) 
            {
                if (this.view) 
                {
                    this.view.hide();
                }
                if (this._codeIco) 
                {
                    this._codeIco.hide();
                }
            }
            return;
        }

        /* internal  */onPromotionCardInfoRes(arg1: MessageBlock): void
        {
            if (ParamsConst.instance.platformCode == "4399" && !this.cache.daily.getIsPromotionCardHadUse(QrCodeConst.CARD_TYPE) && ParamsConst.instance.isShowQrIco == 1) 
            {
                this.codeIco.show();
            }
            return;
        }

        /* internal  */get codeIco(): QrCodeHintBtnView
        {
            if (!this._codeIco) 
            {
                this._codeIco = new QrCodeHintBtnView();
            }
            return this._codeIco;
        }

        /* internal  */hideIco(): void
        {
            this.codeIco.hide();
            return;
        }

        private /* var */_codeIco: QrCodeHintBtnView;
    }
